package com.TCP_UDP网络编程.homeWork;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class TCP1_Server {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(9999);
        Socket socket = serverSocket.accept();

        OutputStream outputStream = socket.getOutputStream();
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(outputStream));

        InputStream inputStream = socket.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
        String str = "";
        while((str = br.readLine()) != null){
            System.out.println(str);
            if(str.equals("name")){
                bw.write("nova");
                bw.flush();
            }else if (str.equals("hobby")){
                bw.write("java");
                bw.flush();
            }else {
                bw.write("what");
                bw.flush();
            }
            bw.newLine();
        }

        br.close();
        socket.close();
        serverSocket.close();

    }
}
